package es.udc.fic.hamNeggs.manager;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import es.udc.fic.hamNeggs.pojo.UserStoriesCategory;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;

@Repository(value = "userStoriesCategories")
public class UserStoriesCategoryManager extends AbstractManager {

    private final static Logger LOG = Logger.getLogger(UserStoriesCommentManager.class.getName());

    @Transactional(readOnly = true)
    @SuppressWarnings("unchecked")
    public List<UserStoriesCategory> getCommentList() {
        List<UserStoriesCategory> list = session.createQuery("from UserStoriesCategory").list();
        Collections.sort(list,
                new Comparator<UserStoriesCategory>() {
                    public int compare(UserStoriesCategory o1, UserStoriesCategory o2) {
                        return o1.getId().intValue() - o2.getId().intValue();
                    }
                });
        return list;
    }

    @Transactional(readOnly = true)
    public UserStoriesCategory getUserStoriesCategory(Long id) {
        return (UserStoriesCategory) session.get(UserStoriesCategory.class, id);
    }

    @Transactional(readOnly = false)
    public void saveUserStoriesCategory(UserStoriesCategory comment) {
        super.save(comment, LOG);
    }

    @Transactional(readOnly = false)
    public void deleteUserStoriesCategory(UserStoriesCategory comment) {
        super.delete(comment, LOG);
    }

    @Transactional(readOnly = false)
    public void updateUserStoriesCategory(UserStoriesCategory comment) {
        super.update(comment, LOG);
    }

}
